__author__    = "Jussi Toivola <jussi@redinnovation.com>"
__copyright__ = "2008 Red Innovation Ltd."
__license__   = "AGPL"
__docformat__ = "epytext"

import _ipc as ipc
import e32
import pylogman as l
#import sys
#sys.stdout.write = l.Log
l.Log( "Server started" )

# Use queue created by the UI.
queue1 = ipc.MsgQueue( u"ui" )
queue1.open()
data_from_ui = queue1.recv( )

# Create our own queue to be used from UI.
queue2 = ipc.MsgQueue( u"server" )
queue2.create( 5 )
try:
    l.Log( "sending data back to UI: %s" % data_from_ui )
    queue2.write( data_from_ui  )
    l.Log( "Sent")

    queue2.write( "Message from another process" )
    l.Log( "Sent, sleeping")
    e32.ao_sleep(5)
    l.Log( "Closing")

    l.Log( "Done")

except Exception, msg:
    l.Log("!!Exception!!")
    l.Log( str( msg ) )
    
queue1.close()
queue2.close()
